home *** CD-ROM | disk | FTP | other *** search
/ Exame Informatica 140 / Exame Informatica 140.iso / Programas / WorldWind / World_Wind_1.4.0_RC2.exe / Plugins / Clock.cs next >
Encoding:
Text File  |  2006-12-18  |  3.6 KB  |  121 lines

  1. //----------------------------------------------------------------------------
  2. // NAME: On-Screen Clock 
  3. // VERSION: 1.1
  4. // DESCRIPTION: Clock sample, adds itself in layer manager - demonstrates adding a renderable object, drawing on screen (C#)
  5. // DEVELOPER: Bjorn Reppen aka "Mashi"
  6. // WEBSITE: http://www.mashiharu.com
  7. //----------------------------------------------------------------------------
  8. //
  9. // This file is in the Public Domain, and comes with no warranty. 
  10. //
  11. using Microsoft.DirectX;
  12. using Microsoft.DirectX.Direct3D;
  13. using System;
  14. using System.Drawing;
  15. using WorldWind;
  16. using WorldWind;
  17. using WorldWind.Renderable;
  18.  
  19. namespace Mashiharu.PluginSample
  20. {
  21.     public class ClockPlugin : WorldWind.PluginEngine.Plugin
  22.     {
  23.         Clock clock;
  24.         
  25.         /// <summary>
  26.         /// Plugin entry point - All plugins must implement this function
  27.         /// </summary>
  28.         public override void Load()
  29.         {
  30.             // Add us to the list of renderable objects - this puts us in the render loop
  31.             clock = new Clock(Application);
  32.             Application.WorldWindow.CurrentWorld.RenderableObjects.Add(clock);
  33.         }
  34.  
  35.         /// <summary>
  36.         /// Unloads our plugin
  37.         /// </summary>
  38.         public override void Unload()
  39.         {
  40.             Application.WorldWindow.CurrentWorld.RenderableObjects.Remove(clock.Name);
  41.         }
  42.     }
  43.  
  44.     /// <summary>
  45.     /// Clock Example : Display the current time 
  46.     /// </summary>
  47.     public class Clock : RenderableObject
  48.     {
  49.         int color2 = Color.Yellow.ToArgb();
  50.         int color = Color.Yellow.ToArgb();
  51.         const int distanceFromCorner = 5;
  52.         MainApplication ww;
  53.  
  54.         public Clock(MainApplication app) : base("Clock", Vector3.Empty, Quaternion.Identity)
  55.         {
  56.             this.ww = app;
  57.             
  58.             // We want to be drawn on top of everything else
  59.             this.RenderPriority = RenderPriority.Icons;
  60.  
  61.             // true to make this layer active on startup, this is equal to the checked state in layer manager
  62.             this.IsOn = true;
  63.         }
  64.  
  65.         /// <summary>
  66.         /// Plugin entry point - All plugins must implement this function
  67.         /// </summary>
  68.         public void Load()
  69.         {
  70.             // Add us to the list of renderable objects - this puts us in the render loop
  71.             ww.WorldWindow.CurrentWorld.RenderableObjects.Add(this);
  72.         }
  73.  
  74.         /// <summary>
  75.         /// This is where we do our rendering 
  76.         /// Called from UI thread = UI code safe in this function
  77.         /// </summary>
  78.         public override void Render(DrawArgs drawArgs)
  79.         {
  80.             // Draw the current time using default font in lower right corner
  81.             string text = DateTime.Now.ToString();
  82.             Rectangle bounds = drawArgs.defaultDrawingFont.MeasureString(null, text, DrawTextFormat.None, 0);
  83.             drawArgs.defaultDrawingFont.DrawText(null, text, 
  84.                 drawArgs.screenWidth-bounds.Width-distanceFromCorner, drawArgs.screenHeight-bounds.Height-distanceFromCorner,
  85.                 color );
  86.         }
  87.  
  88.         /// <summary>
  89.         /// RenderableObject abstract member (needed) 
  90.         /// OBS: Worker thread (don't update UI directly from this thread)
  91.         /// </summary>
  92.         public override void Initialize(DrawArgs drawArgs)
  93.         {
  94.         }
  95.  
  96.         /// <summary>
  97.         /// RenderableObject abstract member (needed)
  98.         /// OBS: Worker thread (don't update UI directly from this thread)
  99.         /// </summary>
  100.         public override void Update(DrawArgs drawArgs)
  101.         {
  102.         }
  103.  
  104.         /// <summary>
  105.         /// RenderableObject abstract member (needed)
  106.         /// OBS: Worker thread (don't update UI directly from this thread)
  107.         /// </summary>
  108.         public override void Dispose()
  109.         {
  110.         }
  111.  
  112.         /// <summary>
  113.         /// RenderableObject abstract member (needed)
  114.         /// Called from UI thread = UI code safe in this function
  115.         /// </summary>
  116.         public override bool PerformSelectionAction(DrawArgs drawArgs)
  117.         {
  118.             return false;
  119.         }
  120.     }
  121. }